package cn.iocoder.yudao.module.handguard.service.userbasetable12;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import cn.iocoder.yudao.module.handguard.controller.app.userbasetable12.vo.*;
import cn.iocoder.yudao.module.handguard.dal.dataobject.userbasetable12.UserBaseTable12DO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import cn.iocoder.yudao.module.handguard.convert.userbasetable12.UserBaseTable12Convert;
import cn.iocoder.yudao.module.handguard.dal.mysql.userbasetable12.UserBaseTable12Mapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.handguard.enums.ErrorCodeConstants.*;

/**
 * 企业流水贷 Service 实现类
 *
 * @author 芋道源码
 */
@Service
@Validated
public class UserBaseTable12ServiceImpl implements UserBaseTable12Service {

    @Resource
    private UserBaseTable12Mapper userBaseTable12Mapper;

    @Override
    public Long createUserBaseTable12(UserBaseTable12CreateReqVO createReqVO) {
        // 插入
        UserBaseTable12DO userBaseTable12 = UserBaseTable12Convert.INSTANCE.convert(createReqVO);
        userBaseTable12Mapper.insert(userBaseTable12);
        // 返回
        return userBaseTable12.getId();
    }

    @Override
    public void updateUserBaseTable12(UserBaseTable12UpdateReqVO updateReqVO) {
        // 校验存在
        validateUserBaseTable12Exists(updateReqVO.getId());
        // 更新
        UserBaseTable12DO updateObj = UserBaseTable12Convert.INSTANCE.convert(updateReqVO);
        userBaseTable12Mapper.updateById(updateObj);
    }

    @Override
    public void deleteUserBaseTable12(Long id) {
        // 校验存在
        validateUserBaseTable12Exists(id);
        // 删除
        userBaseTable12Mapper.deleteById(id);
    }

    private void validateUserBaseTable12Exists(Long id) {
        if (userBaseTable12Mapper.selectById(id) == null) {
            throw exception(USER_BASE_TABLE12_NOT_EXISTS);
        }
    }

    @Override
    public UserBaseTable12DO getUserBaseTable12(Long id) {
        LambdaQueryWrapper<UserBaseTable12DO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(UserBaseTable12DO::getApplicationId,id);
        return userBaseTable12Mapper.selectOne(queryWrapper);
    }

    @Override
    public List<UserBaseTable12DO> getUserBaseTable12List(Collection<Long> ids) {
        return userBaseTable12Mapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<UserBaseTable12DO> getUserBaseTable12Page(UserBaseTable12PageReqVO pageReqVO) {
        return userBaseTable12Mapper.selectPage(pageReqVO);
    }

    @Override
    public List<UserBaseTable12DO> getUserBaseTable12List(UserBaseTable12ExportReqVO exportReqVO) {
        return userBaseTable12Mapper.selectList(exportReqVO);
    }

}
